package com.ehome.poct.base.controller.service;


import cn.hutool.json.JSONUtil;
import com.ehome.poct.base.api.dto.device.bootModule.TestDeviceBootInfoDTO;
import com.ehome.poct.base.api.dto.device.bootModule.TestDeviceBootingDetailDTO;
import com.ehome.poct.base.api.vo.device.BootDetailExportVO;
import com.ehome.poct.base.controller.mapping.BootingInfoMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 开机自检信息服务
 */
@Service
public class BootingInfoService {
    @Autowired
    BootingInfoMapping bootingInfoMapping;

    /**
     * 组装导出需要的信息
     * @param dbData 设备自检原始json数据
     * @return 组装完毕的导出数据
     */
    public List<BootDetailExportVO> buildExportList(List<TestDeviceBootingDetailDTO> dbData){
        return  dbData.parallelStream().collect(ArrayList::new,(list,d)->{
            list.add(bootingInfoMapping.toExport(d.getSno(),d.getCreateTime(), JSONUtil.toBean(d.getResultJson(),TestDeviceBootInfoDTO.class)));
        },ArrayList::addAll);
    }
}
